import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:home/app.dart';

//测试不同依赖，不同方案，成熟后同名替换
Future<void> main() async {
  await beforeRunApp();
  runApp(_MyApp());
}

class _MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    RouteC.setup(() => RouteConfig.loginn);

    return FlutterBoostApp(routeFactory, appBuilder: _appBuilder);
  }

  Route<dynamic> routeFactory(RouteSettings settings, String uniqueId) {
    FlutterBoostRouteFactory func = RouteConfig.routerMap[settings.name];
    if (func == null) {
      return null;
    }
    return func(settings, uniqueId);
  }

  Widget _appBuilder(Widget home) {
    return MaterialApp(
      localizationsDelegates: [
        GlobalWidgetsLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        // 使用：有context？ S.of(context).key ： S.current.key
        S.delegate,
      ],
      supportedLocales: [
        // const Locale('zh_CN', ''),
        ...S.delegate.supportedLocales
      ],
      localeListResolutionCallback: (locales, supportedLocales) {
        debugPrint('locales: ' + locales.toString());
      },
      home: home,
      builder: appBuilder,
    );
  }

  void _onRoutePushed(
      String pageName, String uniqueId, Map params, Route route, Future _) {}
}

class BoostNavigatorObserver extends NavigatorObserver {
  @override
  void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
    print('boost-didPush' + route.settings.name);
  }

  @override
  void didPop(Route<dynamic> route, Route<dynamic> previousRoute) {
    print('boost-didPop' + route.settings.name);
  }

  @override
  void didRemove(Route<dynamic> route, Route<dynamic> previousRoute) {
    print('boost-didRemove' + route.settings.name);
  }

  @override
  void didStartUserGesture(Route<dynamic> route, Route<dynamic> previousRoute) {
    print('boost-didStartUserGesture' + route.settings.name);
  }
}
